package com.film.controller.user;

import com.alibaba.fastjson.JSONObject;
import com.film.jwt.JwtUtil;
import com.film.service.impl.user.FetchUserInfoServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.sql.SQLException;

//拉取用户信息，用于渲染个人页面，包括头像、名称、喜欢的电影
@RestController
public class FetchUserInfoController {
    @Autowired
    private FetchUserInfoServiceImpl fetchUserInfoService;

    @GetMapping("/user/getInfo/{username}/{token}")
    public JSONObject getInfo(@PathVariable String username, @PathVariable String token) throws SQLException {
        if (!JwtUtil.JwtVerify(token)) {
            JSONObject resp = new JSONObject();
            resp.put("error_message", "jwt验证错误");
            return resp;
        } else {
            return fetchUserInfoService.gerUserInfo(username);
        }
    }
}
